1. /* sdfatnhs.cpp by K.Tsuru */
  2. // function ID 3312 DRADIX
  3. /*********************************************************
  4. SDouble class
  5. inverse hyperbolic function atanh(x) by series expansion
  6. atanh(x) = 0.5*log{(1+x)/(1-x)} = x + x^3/3+x^5/5 + ...
  7. x can be negative and |x| < 1.0.
  8. ***********************************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. static const char* func= "AtanhSeries";
  13. SDouble AtanhSeries(const SDouble& x){
  14. // if(x.SNSign() == 0) return x; do not check x == 0
  15. SDouble x1(x), x2(x*x), result(x), delta;
  16. if(x.NetRdxExp() > 0) x.SetError(x.DOMAIN_ERR, func, 3312); // |x| > 1.0
  17. x1.FixedPoint(x.RdxExp());
  18. ulong k = 3uL, mt = x.SlOpMaxValue();
  19. do{
  20. x1 *= x2;
  21. delta = DsDiv(x1, k);
  22. result += delta;
  23. if( (k += 2) >= mt ){
  24. result.SetError(result.NOT_CONVERGE, func, -3312);
  25. break;
  26. }
  27. } while(delta.Sign(3312));
  28. x.upToTerm = (k+1uL)/2uL;
  29. x1.PointFree(); //Must use the object which called FixedPoint().
  30. result.Reform(3312);
  31. return result;
  32. }

sdfatnhs.cpp : last modifiled at 2007/11/29 00:05:48(1,049 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).